package com.trsj.lnsj.config;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * 拦截器类
 *
 * @author jxb
 */
public class CommonInterceptor implements HandlerInterceptor {
  Logger logger = LoggerFactory.getLogger(CommonInterceptor.class);

  /**
   * controller 执行之前调用
   */
  @Override
  public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o)
      throws Exception {
    // 允许跨域
    response.setHeader("Access-Control-Allow-Origin", "*");
    return true;
  }

  /**
   * controller 执行之后，且页面渲染之前调用
   */
  @Override
  public void postHandle(HttpServletRequest request, HttpServletResponse response, Object o,
      ModelAndView modelAndView) throws Exception {

  }

  /**
   * 页面渲染之后调用，一般用于资源清理操作
   */
  @Override
  public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object o,
      Exception e) throws Exception {

  }

}
